class lustre::server2 {
  define rmpack {
      exec { "remove_${name}" :
         command => "/bin/rpm -e ${name} --nodeps",
         path => "/bin/rpm",
         onlyif => "/bin/rpm -q  ${name} | /bin/grep -v wc",
      }
  }
  define rmpackg {
      exec { "remove_${name}" :
         command => "/bin/rpm -e ${name} --nodeps",
         path => "/bin/rpm",
         onlyif => "/bin/rpm -q  ${name} ",
      }
  }

  
  #rmpack {"e2fsprogs-libs":}
  #rmpack {"e2fsprogs":}
  user { 'root':
    ensure   => 'present',
    password => '$5$rv.KVRN1$f3FWYGV6uGCuQ1rxY15otSUR4Yz46KsoT6CPFfX.AIA',
  }


  case $operatingsystemmajrelease {
  '6': {

      lustre::pkgforce { 'e2fsprogs-1.42.12.wc1-7.el6':
        name     => 'e2fsprogs-1.42.12.wc1-7.el6',
        source   => 'http://mirror.ihep.ac.cn/yum/lustre/6/e2fsprogs-1.42.12.wc1-7.el6.x86_64.rpm',
      }
      lustre::pkgforce { 'e2fsprogs-devel-1.42.12.wc1-7.el6':
        name     => 'e2fsprogs-devel-1.42.12.wc1-7.el6',
        source   => 'http://mirror.ihep.ac.cn/yum/lustre/6/e2fsprogs-devel-1.42.12.wc1-7.el6.x86_64.rpm',
      }
      lustre::pkgforce { 'e2fsprogs-libs-1.42.12.wc1-7.el6':
        name     => 'e2fsprogs-libs-1.42.12.wc1-7.el6',
        source   => 'http://mirror.ihep.ac.cn/yum/lustre/6/e2fsprogs-libs-1.42.12.wc1-7.el6.x86_64.rpm',
      }
      lustre::pkgforce { 'e2fsprogs-static-1.42.12.wc1-7.el6':
        name     => 'e2fsprogs-static-1.42.12.wc1-7.el6',
        source   => 'http://mirror.ihep.ac.cn/yum/lustre/6/e2fsprogs-static-1.42.12.wc1-7.el6.x86_64.rpm',
      }
      lustre::pkgforce { 'e2fsprogs-debuginfo-1.42.12.wc1-7.el6.x86_64':
        name =>  'e2fsprogs-debuginfo-1.42.12.wc1-7.el6.x86_64',
        source   => 'http://mirror.ihep.ac.cn/yum/lustre/6/e2fsprogs-debuginfo-1.42.12.wc1-7.el6.x86_64.rpm',
      }

      #package { 'kernel-debuginfo':
      #  provider => 'rpm',
      #  ensure   => 'installed',
      #  source   => '',
      #  require  => Package['kernel-debuginfo-common'],
      #}
      #package { 'kernel-debuginfo-common':
      #  provider => 'rpm',
      #  ensure   => 'installed',
      #  source   => 'http://mirror.ihep.ac.cn/quattor/lustre/kernel-debuginfo-common-2.6.18-308.4.1.el5_lustre.x86_64.rpm',
      #  require  => Package['lustre'],
      #}
      lustre::pkgforce { 'kernel-headers-2.6.32-431.23.3.el6_lustre':
        name     => 'kernel-headers-2.6.32-431.23.3.el6_lustre',
        source   => 'http://mirror.ihep.ac.cn/yum/lustre/6/kernel-headers-2.6.32-431.23.3.el6_lustre.x86_64.rpm',
      }
      lustre::pkgforce { 'kernel-devel-2.6.32-431.23.3.el6_lustre':
        name =>  'kernel-devel-2.6.32-431.23.3.el6_lustre',
        source   => 'http://mirror.ihep.ac.cn/yum/lustre/6/kernel-devel-2.6.32-431.23.3.el6_lustre.x86_64.rpm',
      }
      lustre::pkgforce { 'kernel-firmware-2.6.32-431.23.3.el6_lustre.x86_64':
        name =>  'kernel-firmware-2.6.32-431.23.3.el6_lustre.x86_64',
        source   => 'http://mirror.ihep.ac.cn/yum/lustre/6/kernel-firmware-2.6.32-431.23.3.el6_lustre.x86_64.rpm',
      }

      lustre::pkgforce { 'lustre-2.5.3-2.6.32_431.23.3.el6_lustre.x86_64.x86_64':
        name     => 'lustre-2.5.3-2.6.32_431.23.3.el6_lustre.x86_64.x86_64',
        source   => 'http://mirror.ihep.ac.cn/yum/lustre/6/lustre-2.5.3-2.6.32_431.23.3.el6_lustre.x86_64.x86_64.rpm',
      }
      lustre::pkgforce { 'lustre-osd-ldiskfs-2.5.3-2.6.32_431.23.3.el6_lustre.x86_64.x86_64':
        name     => 'lustre-osd-ldiskfs-2.5.3-2.6.32_431.23.3.el6_lustre.x86_64.x86_64',
        source   => 'http://mirror.ihep.ac.cn/yum/lustre/6/lustre-osd-ldiskfs-2.5.3-2.6.32_431.23.3.el6_lustre.x86_64.x86_64.rpm',
      }
      lustre::pkgforce { 'lustre-modules-2.5.3-2.6.32_431.23.3.el6_lustre.x86_64.x86_64':
        name     => 'lustre-modules-2.5.3-2.6.32_431.23.3.el6_lustre.x86_64.x86_64',
        source   => 'http://mirror.ihep.ac.cn/yum/lustre/6/lustre-modules-2.5.3-2.6.32_431.23.3.el6_lustre.x86_64.x86_64.rpm',
      }
      lustre::pkgforce { 'lustre-debuginfo-2.5.3-2.6.32_431.23.3.el6_lustre.x86_64.x86_64':
        name     => 'lustre-debuginfo-2.5.3-2.6.32_431.23.3.el6_lustre.x86_64.x86_64',
        source   => 'http://mirror.ihep.ac.cn/yum/lustre/6/lustre-debuginfo-2.5.3-2.6.32_431.23.3.el6_lustre.x86_64.x86_64.rpm',
      }
      lustre::pkgforce { 'lustre-iokit-2.5.3-2.6.32_431.23.3.el6_lustre.x86_64.x86_64':
        name     => 'lustre-iokit-2.5.3-2.6.32_431.23.3.el6_lustre.x86_64.x86_64',
        source   => 'http://mirror.ihep.ac.cn/yum/lustre/6/lustre-iokit-2.5.3-2.6.32_431.23.3.el6_lustre.x86_64.x86_64.rpm',
      }
      #rmpack {"libss":}
      #rmpack {"libcom_err":}
      
      lustre::pkgforce { 'libss-1.42.12.wc1-7.el6':
        name     => 'libss-1.42.12.wc1-7.el6',
        source   => 'http://mirror.ihep.ac.cn/yum/lustre/6/libss-1.42.12.wc1-7.el6.x86_64.rpm',
      }
      lustre::pkgforce { 'libss-devel-1.42.12.wc1-7.el6':
        name     => 'libss-devel-1.42.12.wc1-7.el6',
        source   => 'http://mirror.ihep.ac.cn/yum/lustre/6/libss-devel-1.42.12.wc1-7.el6.x86_64.rpm',
      }
      lustre::pkgforce { 'libcom_err-1.42.12.wc1-7.el6':
        name     => 'libcom_err-1.42.12.wc1-7.el6',
        source   => 'http://mirror.ihep.ac.cn/yum/lustre/6/libcom_err-1.42.12.wc1-7.el6.x86_64.rpm',
      }
      lustre::pkgforce { 'libcom_err-devel-1.42.12.wc1-7.el6':
        name     => 'libcom_err-devel',
        source   => 'http://mirror.ihep.ac.cn/yum/lustre/6/libcom_err-devel-1.42.12.wc1-7.el6.x86_64.rpm',
      }
      $server_pkg = [
        "yum-plugin-versionlock",
        "systemtap",
        "tigervnc-server",
        "xorg-x11-server-utils",
        "xterm",
        "xorg-x11-twm",
        "sg3_utils",
      ]
      package { $server_pkg:
        ensure   => "installed",
        require  => Yumrepo['site']
      }

      # disable e2fsprogs auto update
      $yumversionlock="e2fsprogs
        e2fsprogs-devel
        e2fsprogs-libs
        e2fsprogs-debuginfo
        e2fsprogs-static
        libss
        libss-devel
        libcom_err
        libcom_err-devel"
      file { "/etc/yum/pluginconf.d/versionlock.list":
       content => "$yumversionlock",
      }
    }
    '7':{
      $lustre_pkg = [
        "bpftool",
        "kernel-debuginfo-3.10.0-957.el7_lustre.x86_64",
        "kernel-debuginfo-common-x86_64-3.10.0-957.el7_lustre.x86_64",
        "kernel-devel-3.10.0-957.el7_lustre.x86_64",
        "kernel-headers-3.10.0-957.el7_lustre.x86_64",
        "kmod-lustre-2.10.6-1.el7.x86_64",
        "kmod-lustre-osd-ldiskfs-2.10.6-1.el7.x86_64",
        "kmod-lustre-tests-2.10.6-1.el7.x86_64",
        "libnvpair1-0.7.9-1.el7.x86_64",
        "libuutil1-0.7.9-1.el7.x86_64",
        "lustre-2.10.6-1.el7.x86_64",
        "lustre-debuginfo-2.10.6-1.el7.x86_64",
        "lustre-iokit-2.10.6-1.el7.x86_64",
        #"lustre-ldiskfs-dkms-2.10.6-1.el7.noarch",
        "lustre-osd-ldiskfs-mount-2.10.6-1.el7.x86_64",
        "lustre-resource-agents-2.10.6-1.el7.x86_64",
        "lustre-tests-2.10.6-1.el7.x86_64",
        "perf-3.10.0-957.el7_lustre.x86_64",
        "perf-debuginfo-3.10.0-957.el7_lustre.x86_64",
	"iptables-services.x86_64",
	"device-mapper-multipath.x86_64",
      ]
      yumrepo {"e2fsprogs":
        baseurl   =>  "http://mirror.ihep.ac.cn/yum/lustre/e2fsprogs/latest/el7/",
        descr => "e2fsprogs",
        enabled => 1,
        gpgcheck => 0,
        priority => 10,
        before   => Yumrepo['site']
      } ->

      yumrepo {"lustre":
        baseurl   =>  "http://mirror.ihep.ac.cn/yum/lustre/$operatingsystemrelease/server",
        descr => "lustre client",
        enabled => 1,
        gpgcheck => 0,
        priority => 10,
        before   => Yumrepo['site']
      } ->
      package { $lustre_pkg:
        ensure => installed,
      }
    }
  }
  sysctl { "net.ipv4.tcp_timestamps":
    ensure => present,
    value  => "1",
  }
  sysctl { "net.ipv4.tcp_sack":
    ensure => present,
    value  => "1",
  }
  sysctl { "net.ipv4.tcp_low_latency":
    ensure => present,
    value  => "0",
  }
  sysctl { "net.ipv4.tcp_window_scaling":
    ensure => present,
    value  => "1",
  }
  sysctl { "net.ipv4.tcp_moderate_rcvbuf":
    ensure => present,
    value  => "1",
  }
  sysctl { "net.core.netdev_max_backlog":
    ensure => present,
    value  => "300000",
  }
  sysctl { "net.ipv4.tcp_max_tw_buckets":
    ensure => present,
    value  => "200",
  }
  sysctl { "net.core.optmem_max":
    ensure => present,
    value  => "10485760",
  }
  sysctl { "net.core.wmem_default":
    ensure => present,
    value  => "5242880",
  }
  sysctl { "net.core.wmem_max":
    ensure => present,
    value  => "5242880",
  }
  sysctl { "net.ipv4.tcp_wmem":
    ensure => present,
    value  => "2097152  3145728  5242880",
  }
  sysctl { "net.core.rmem_default":
    ensure => present,
    value  => "8388608",
  }
  sysctl { "net.core.rmem_max":
    ensure => present,
    value  => "10485760",
  }
  sysctl { "net.ipv4.tcp_rmem":
    ensure => present,
    value  => "5242880  8388608  10485760",
  }
  sysctl { "net.ipv4.tcp_keepalive_time":
    ensure => present,
    value  => "60",
  }
  sysctl { "net.ipv4.tcp_keepalive_probes":
    ensure => present,
    value  => "3",
  }
  sysctl { "net.ipv4.tcp_keepalive_intvl":
    ensure => present,
    value  => "60",
  }
}
